<?php
namespace app\http\middleware;

class CheckAuth 
{
    public function handle($request, \Closure $next)
    {
    	if(session('uid')!=1){
    		$ctl=request()->controller();
			$act=request()->action();
			$data = model("SystemModule")->where(['ctl'=>$ctl,'act'=>$act])->find();
			if($data !== null){
				$role = model("admin")->where("admin_id",session("uid"))->select();
				$allper=model('Access')->getAllPer($role[0]['role_id']);
				if(!in_array($data['mod_id'], $allper)){
					return redirect('admin/index/index')->with('msg','您没有权限访问')->with('code',0);
				}
			}else{
				return redirect('admin/index/index')->with('msg','页面不存在')->with('code',0);
			}
    	}
		return $next($request);
    }
}
